package com.siwei.mes.controller.system;

import com.siwei.mes.common.query.PageQuery;
import com.siwei.mes.common.result.ApiResult;
import com.siwei.mes.common.result.Json;
import com.siwei.mes.common.validator.AddGroup;
import com.siwei.mes.common.validator.PageGroup;
import com.siwei.mes.common.validator.UpdateGroup;
import com.siwei.mes.entity.system.ProjectArea;
import com.siwei.mes.service.system.ProjectAreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @program: mes-platform
 * @description: 工程区域划分表
 * @author: yangke
 * @create: 2023-12-17 15:4p8
 **/
@Api(value = "工程区域划分表")
@RestController
@RequestMapping("projectArea")
public class ProjectAreaController {
    @Resource
    private ProjectAreaService projectAreaService;

    @ApiOperation(value = "新增工程区域划分表")
    @PostMapping("/create")
    public Json create(@RequestBody @Validated(AddGroup.class) ProjectArea entity) {
        return Json.succ().data(ApiResult.addColumn("id", projectAreaService.create(entity)));
    }

    @ApiOperation(value = "修改工程区域划分表")
    @PostMapping("/update")
    public Json update(@RequestBody @Validated(UpdateGroup.class) ProjectArea entity) {
        projectAreaService.update(entity);
        return Json.succ().data(new ApiResult());
    }

    @ApiOperation(value = "删除工程区域划分表")
    @PostMapping("/delete")
    public Json delete(@RequestBody ProjectArea entity) {
        projectAreaService.delete(entity.getId());
        return Json.succ().data(new ApiResult());
    }

    @ApiOperation(value = "分页获取工程区域划分表")
    @PostMapping("/page")
    public Json appPage(@RequestBody @Validated(PageGroup.class) PageQuery<ProjectArea, ProjectArea> query) {
        return Json.succ().data(projectAreaService.getPage(query));
    }

    @ApiOperation(value = "根据主键id获取工程区域划分表")
    @GetMapping("loadById")
    public Json loadById(@RequestParam("id") Long id) {
        return Json.succ().data(projectAreaService.loadById(id));
    }

    @ApiOperation(value = "获取所有工程区域划分表")
    @PostMapping("getAll")
    public Json getAll(@RequestBody ProjectArea entity) {
        return Json.succ().data(ApiResult.addList(projectAreaService.getAll(entity)));
    }
}
